﻿@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base;
<script>
    function modifyUser(id) {
        ajaxLoad('initload', '@Html.Raw(Url.Action("UserModify", "Admin_User"))?userid=' + id);

    }
    //用户全选
    function groupcheckall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxuser input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxuser input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxuser input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.userall").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxuser input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.userall").removeAttr("checked", "checked");
            }
            else {
                $("input.userall").attr("checked", "checked");
            }
        }

    })
    //删除用户
    function deluserlist() {
        var ckbs = $(".checkboxuser input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        var checkedstr = [];
        ckbs.each(function () {
            checkedstr.push($(this).val());
        })
        delfunc(checkedstr.toString());

    }
    function delfunc(idstr) {
        confirmDialog('确定要删除吗?', function () {
            $.ajax({
                type: "GET",
                url: "@Html.Raw(Url.Action("delUser", "Admin_User"))?idlist=" + idstr,
                success: function (m) {
                    if (m == "True") {
                        messageAlert("操作成功！");
                        //刷新
                        $('#pageIndexNow').val(1);
                        SearchUserData();
                    }
                    else {
                        messageAlert("操作失败！");
                    }
                },
                error: function (e)
                { }
            })
        });
    }
    //数据库权限设置
    function dbUserAuth(userid) {
        ajaxLoad("initload", '@Html.Raw(Url.Action("DBAuthList", "Admin_User"))?id=' + userid + '&flage=0');  //flage  1代表用户组数据库权限，0代表用户数据库权限设置
    }
</script>

<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
    <thead>
        <tr class="thead">
            <th class="tdnum">
                <input type="checkbox" class="userall" value="" name="" onclick="groupcheckall(this)">序号</th>
            <th class=''>账号</th>
            <th class='tl'>是否停用</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{if (ViewBag.UserList != null)
          {
              int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
              foreach (SYS_CMS_USER item in ViewBag.UserList)
              {
                  if (ColumnAliasHelper.GetContentNoRed(item.Username).ToUpper() == "SA")
                  {
                      continue;
                  }
                  string str = "even";
                  if (sortno % 2 == 0)
                  {
                      str = "odd";
                  }
            <tr class='@str'>
                <td class="checkboxuser">
                    @{ string name = ColumnAliasHelper.GetContentNoRed(item.Username).ToUpper();
                       if (name != "SA" && name != "GUEST" && name != "ANONY")
                       {
                        <input type="checkbox" value="@item.SysID"  >@sortno
                       }
                       else
                       {
                        @sortno
                       }
                    }
                </td>
                <td>@Html.Raw(ColumnAliasHelper.SubContent(item.Username, item.Username.Length))</td>
                <td>
                    @if (item.StopFlag == 1)
                    {<i class="iconfont icon-close2 red"></i>}
                    else
                    {<i class="iconfont  icon-correct3 success"></i>}
                </td>
                <td class="tc">
                    @if (name == "SA")
                    {
                        <a style="visibility: hidden" href="javascript:void(0)">数据库权限设置</a>
                    }
                    else
                    {
                        <a  href="javascript:void(0);" onclick="dbUserAuth('@item.SysID')">数据库权限设置</a>
                    }
                    <a onclick="modifyUser('@item.SysID')" href="javascript:void(0)">修改设置</a>
                    @{if (name == "SA" || name == "GUEST" || name == "ANONY")
                      {
                        <a style="visibility: hidden" href="javascript:void(0)">删除</a>
                      }
                      else
                      {
                        <a onclick="delfunc('@item.SysID')" href="javascript:void(0)">删除</a>
                      }
                    }
                </td>
            </tr>
                      sortno = sortno + 1;
              }
          }

        }
    </tbody>
</table>


@*//分页*@
<div class="pagenav pagenav-02">
    @*上一页*@
    @if (ViewBag.TotalPage > 0)
    {
        if (ViewBag.PageNow != 1)
        {
            int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">上一页</a>
        }
@*循环初始化页码*@
        foreach (string numpage in ViewBag.PageList)
        {
            if (numpage != "0")
            {
                int m = int.Parse(numpage);
                if (m == ViewBag.PageNow)
                {
        <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                }
                else
                {
        <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                }

            }
            else
            {
        <i class="iconfont icon-dian2"></i>
            }

        }
@*下一页*@
        if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
        {
            int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">下一页</a>
        }
    }
    @if (@ViewBag.Count == 0)
    {
        <label>暂无数据！</label>
        
    }
    else
    {
          
        <label>共 </label>
        <label>@ViewBag.Count </label>
        <label>条数据 </label>
    }
</div>

<div class='posr'>
    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="ajaxLoad('initload','@Html.Raw(Url.Action("UserManager", "Admin_User"))')">添加</a>
    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="deluserlist()">删除</a>
</div>


